package com.crazyice.lee.reader;

import com.crazyice.lee.data.School;
import com.crazyice.lee.data.Student;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;

import java.util.Random;

@Slf4j
public class SchoolList extends RichParallelSourceFunction<School> {
    private boolean isRun=true;

    @Override
    public void run(SourceContext<School> sourceContext) throws Exception {
        Random random=new Random();
        int number=0;
        while (isRun){
            number++;
            School school=new School();
            school.setSchoolId(number);
            school.setOrderId(number);
            school.setStudentNumber(100+random.nextInt(435));
            sourceContext.collect(school);
            if (number>=100)break;
        }

    }

    @Override
    public void cancel() {
        isRun=false;
    }
}
